package com.banshou.installs.presenter;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import com.banshou.installs.R;
import com.banshou.installs.constant.BaseApplication;
import com.banshou.installs.model.net.RetrofitManager;
import com.banshou.installs.ui.activity.StaffManagerActivity;
import com.banshou.installs.utils.DialogUtils;
import com.orhanobut.logger.Logger;

import java.util.Map;

import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by cjq on 2018/1/2.
 * Email: stoic_yb@139.com
 * features:
 */

public abstract class BasePresenter {
    private BasePresenterView basePresenterView;
    public RetrofitManager retrofitManager;

    public BasePresenter(BasePresenterView view){
        this.basePresenterView = view;
        this.retrofitManager = RetrofitManager.getInstance();
    }

    public <T> void getData(Map<String,String> parmas,Class<T> T){
        getData(parmas,T,1);
    }

    public <T> void getData(Map<String, String> parmas, Class<T> T, final int i){
        retrofit2.Call<T> call = getCall(parmas);
        call.enqueue(new Callback<T>() {
            @Override
            public void onResponse(retrofit2.Call<T> call, Response<T> response) {
                Logger.d(response.toString());
                T body = response.body();
                basePresenterView.success(body,i);
            }

            @Override
            public void onFailure(retrofit2.Call<T> call, Throwable t) {
                Logger.d(t.toString());
                basePresenterView.failure(t.toString());
            }
        });
    }

    public abstract <T> retrofit2.Call<T> getCall(Map<String, String> parmas);
}
